package com.huoyun.channel.action;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.huoyun.base.action.BaseAction;
import com.huoyun.base.bean.Page;
import com.huoyun.car.model.CarUserCompanyModel;
import com.huoyun.car.service.evt.GetCarPubsByCityEvt;
import com.huoyun.car.service.evt.QueryCarEvt;
import com.huoyun.car.service.CarPubInfoService;
import com.huoyun.car.service.CarRouteService;
import com.huoyun.car.service.CarService;
import com.huoyun.cargo.model.CargoUserCompanyModel;
import com.huoyun.cargo.service.CargoService;
import com.huoyun.cargo.service.evt.GetCargoByCityEvt;
import com.huoyun.cargo.service.evt.QueryCargoEvt;

import com.huoyun.order.service.OrderService;
import com.huoyun.order.service.evt.GetOrderForIndexEvt;
import com.huoyun.order.service.evt.QueryOrderListEvt;

public class HomeAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6332596129378392784L;
	private CargoService cargoService;
	private CarPubInfoService carPubInfoService;
	private CarRouteService carRouteService;
	private CarService carService;
	private OrderService orderService;
	
	private Page cargoPage;
	private Page carPage;
	private Page orderPage;
	
	private String cargoProvince;
	private String cargoCity;
	
	//车源信息的起始地
	private String carProvince;
	private String carCity;
	
	//成交信息
	private long orderCountYesterday;
	private	String orderPriceSumYesterday;
	
	private long newCarCount;
	private long newCargoCount;
	
	/**
	 * 频道标示
	 */
	private String menu = "home";

	/**
	 * 注册页面展示的最新货源信息
	 */
	private List<CargoUserCompanyModel> cargoUserCompanyList;
	
	/**
	 * 注册页面展示的最新注册车辆信息
	 */
	private List<CarUserCompanyModel> carUserCompanyList;
	
	public String index(){
		try {
			GetCargoByCityEvt evt=new GetCargoByCityEvt();
			evt.setProvince("1");
			evt.setPageCount(8);
			evt.setPageNo(pageNo);
			cargoPage=cargoService.getCargoByCity(evt);
			
			
			GetCarPubsByCityEvt carPubsEvt=new GetCarPubsByCityEvt();
			carPubsEvt.setProvince("1");
			carPubsEvt.setPageCount(8);
			carPubsEvt.setPageNo(pageNo);
			carPage=carPubInfoService.getCarPubsByCity(carPubsEvt);
			
			GetOrderForIndexEvt getOrderForIndexEvt=new GetOrderForIndexEvt();
			
			getOrderForIndexEvt.setPageCount(10);
			getOrderForIndexEvt.setPageNo(pageNo);
			
			orderPage=orderService.getOrderForIndex(getOrderForIndexEvt);
			
			Calendar cal  = Calendar.getInstance();  
			cal.add(Calendar.DATE, -1);  
			Date yesterday  = cal.getTime(); 
			
			
			orderPage=orderService.getOrderForIndex(getOrderForIndexEvt);
			QueryOrderListEvt evt1=new QueryOrderListEvt();
			evt1.setAddTime(yesterday);
			orderCountYesterday=orderService.queryOrderCount(evt1);
			orderPriceSumYesterday=orderService.queryOrderMoney(evt1);
			
			QueryCarEvt carEvt=new QueryCarEvt();
			carEvt.setAddTime(yesterday);
			newCarCount=carService.queryCarCount(carEvt);
			QueryCargoEvt cargoEvt=new QueryCargoEvt();
			cargoEvt.setAddTime(yesterday);
			newCargoCount=cargoService.queryCargoCount(cargoEvt);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String cargoListIndex(){
		try {
			GetCargoByCityEvt evt=new GetCargoByCityEvt();
			evt.setProvince(cargoProvince);
			evt.setCity(cargoCity);
			evt.setPageCount(8);
			evt.setPageNo(pageNo);
			cargoPage=cargoService.getCargoByCity(evt);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	public String carListIndex(){
		try {
			GetCarPubsByCityEvt evt=new GetCarPubsByCityEvt();
			evt.setProvince(carProvince);
			evt.setCity(carCity);
			evt.setPageCount(8);
			evt.setPageNo(pageNo);
			carPage=carPubInfoService.getCarPubsByCity(evt);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	public String latestCargoAndCar(){
		System.out.println("yangyang");
		cargoUserCompanyList=cargoService.getLatestNCargo(5);
		carUserCompanyList=carService.getLatestNCar(5);
		return SUCCESS;
	}
	
	
	public CargoService getCargoService() {
		return cargoService;
	}
	public void setCargoService(CargoService cargoService) {
		this.cargoService = cargoService;
	}
	public CarPubInfoService getCarPubInfoService() {
		return carPubInfoService;
	}
	public void setCarPubInfoService(CarPubInfoService carPubInfoService) {
		this.carPubInfoService = carPubInfoService;
	}

	public Page getCargoPage() {
		return cargoPage;
	}

	public void setCargoPage(Page cargoPage) {
		this.cargoPage = cargoPage;
	}

	public String getCargoProvince() {
		return cargoProvince;
	}

	public void setCargoProvince(String cargoProvince) {
		this.cargoProvince = cargoProvince;
	}
	
	public CarRouteService getCarRouteService() {
		return carRouteService;
	}

	public void setCarRouteService(CarRouteService carRouteService) {
		this.carRouteService = carRouteService;
	}

	public String getCargoCity() {
		return cargoCity;
	}

	public void setCargoCity(String cargoCity) {
		this.cargoCity = cargoCity;
	}

	public String getCarProvince() {
		return carProvince;
	}

	public void setCarProvince(String carProvince) {
		this.carProvince = carProvince;
	}

	public String getCarCity() {
		return carCity;
	}

	public void setCarCity(String carCity) {
		this.carCity = carCity;
	}

	public Page getCarPage() {
		return carPage;
	}

	public void setCarPage(Page carPage) {
		this.carPage = carPage;
	}

	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public Page getOrderPage() {
		return orderPage;
	}

	public void setOrderPage(Page orderPage) {
		this.orderPage = orderPage;
	}

	public long getOrderCountYesterday() {
		return orderCountYesterday;
	}

	public void setOrderCountYesterday(long orderCountYesterday) {
		this.orderCountYesterday = orderCountYesterday;
	}

	public String getOrderPriceSumYesterday() {
		return orderPriceSumYesterday;
	}

	public void setOrderPriceSumYesterday(String orderPriceSumYesterday) {
		this.orderPriceSumYesterday = orderPriceSumYesterday;
	}

	public long getNewCarCount() {
		return newCarCount;
	}

	public void setNewCarCount(long newCarCount) {
		this.newCarCount = newCarCount;
	}

	public long getNewCargoCount() {
		return newCargoCount;
	}

	public void setNewCargoCount(long newCargoCount) {
		this.newCargoCount = newCargoCount;
	}

	public CarService getCarService() {
		return carService;
	}

	public void setCarService(CarService carService) {
		this.carService = carService;
	}

	public List<CargoUserCompanyModel> getCargoUserCompanyList() {
		return cargoUserCompanyList;
	}

	public void setCargoUserCompanyList(
			List<CargoUserCompanyModel> cargoUserCompanyList) {
		this.cargoUserCompanyList = cargoUserCompanyList;
	}

	public List<CarUserCompanyModel> getCarUserCompanyList() {
		return carUserCompanyList;
	}

	public void setCarUserCompanyList(List<CarUserCompanyModel> carUserCompanyList) {
		this.carUserCompanyList = carUserCompanyList;
	}
	
	public String getMenu() {
		return menu;
	}
	
}
